<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="#">系统管理</a>
        </li>

        <li>
            <a href="#">用户列表</a>
        </li>
    </ul>
    <div>
        <input type="hidden" id="cupage" value="1"/>
        <input type="hidden" id="total" value="1"/>
        <input type="hidden" id="formurl" value="/manager/system/getManagerUserPage"/>
        <input type="hidden" id="startTime" value=""/>
        <input type="hidden" id="endTime" value=""/>
        <input type="hidden" name="user_id" id="user_id"/>
        <input type="hidden" name="car" id="car"/>
    </div>
</div>

<div class="page-content">
    <div class="row">
        <div class="col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">
                        <i class="icon-reorder"></i>
                        用户列表
                    </h3>
                    <div class="btn-add-pikaqiu">
                        <button class="btn btn-xs" data-toggle="modal" data-target="#managerUserAddModal"><i class="icon-plus"></i> 添 加</button>
                    </div>
                </div>
                <div class="panel-body">
                    <div class="table-responsive">
                        <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                            <thead>
                            <tr>
                                <th>用户编号</th>
                                <th>登录名</th>
                                <th>姓名</th>
                                <th>手机号</th>
                                <th>创建时间</th>
                                <th>最后登录时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody id="loadData">

                            </tbody>
                        </table>
                        <!--#include file="/admin/include/page.html"-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="managerUserAddModal" tabindex="-1" role="dialog" aria-labelledby="managerUserAddModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">添加用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form">
                    <input type="hidden" id="userid">
                    <div class="form-group">
                        <label for="username" class="col-sm-2 control-label">用户名</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="username" placeholder="请输入用户名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="realname" class="col-sm-2 control-label">真实姓名</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="realname" placeholder="请输入真实姓名">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="phone" class="col-sm-2 control-label">手机号码</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="phone" placeholder="请输入手机号码">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="addManagerUser()">提交更改</button>
            </div>
        </div>
    </div>
</div>

<script>
    $("#btn-load").on("click", function () {
        var a = $(this);
        a.button("loading");
        $("#cupage").val("1");
        loadData();
    });

    function loadData() {
        var tempKey = $("#tempKey").val();
        var tempvalue = $("#tempValue").val();
        var para = {
            curPage: $("#cupage").val(),
            tempKey: tempKey,
            tempvalue: tempvalue
        };
        loadGetServer($("#formurl").val(), para, function (data) {
            var $loadData = $("#loadData");
            $loadData.html("");
            var list = data.page.list;
            var html_ = "";
            for (var i = 0; i < list.length; i++) {
                html_ += "<tr><td>" + list[i].id + "</td><td>" + list[i].username + "</td><td>" + replaceNull(list[i].realname,'') + "</td><td>" + list[i].phone + "</td>";
                html_ += "<td>" + list[i].create_date + "</td><td>" + replaceNull(list[i].login_date,'') + "</td>";
                html_ += "<td><div class='hidden-sm hidden-xs btn-group'>";
                html_ += "<button class='btn btn-xs btn-info' title='重置密码' onclick='showConfirm(" + list[i].id + ")'><i class='icon-refresh bigger-120'></i>重置密码</button>";
                html_ += "</div></td></tr>";
            }
            $loadData.html(html_);
            pageValue(data);
            pageData();
            $("#btn-load").button("reset");
        });
    }

    loadData();

    function resetPwd(userid){
        loadGetServer('/manager/system/resetUserPwd', {userId:userid}, function (data) {
            if(data.code!=0){
                alert(data.msg);
            } else{
                alert('操作成功')
            }
        });
    }

    function showConfirm(userid) {
        var r = confirm("是否确定重置此用户密码？");
        if (r == true) {
            resetPwd(userid)
        }
    }

    function addManagerUser(){
        var para = {
            userid: $("#userid").val(),
            username: $("#username").val(),
            realname: $("#realname").val(),
            phone: $("#phone").val()
        };
        loadGetServer('/manager/system/addManagerUser', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                alert('操作成功')
                $('#managerUserAddModal').modal('hide');
            }
            loadData();
        });
    }

    function editMenu(menuId){
        var para = {
            id: menuId
        };
        loadGetServer('/manager/menu/getMenu', para, function (data) {
            if(data.code != 0){
                alert(data.msg);
            }else{
                $('#menuAddModal').modal('show');
                $("#userid").val(data.data.id);
                $("#username").val(data.data.username);
                $("#realname").val(data.data.realname);
            }
            loadData();
        });
    }
</script>